package cshi.java8;

import java.util.concurrent.CompletableFuture;

public class Async {
    public static void main(String[] args) {
        // https://dzone.com/articles/parallel-and-asynchronous-programming-in-java-8
        // 以下的then函数都有Async接口，如果指定了，表明回调将在单独的线程上运行
        CompletableFuture.supplyAsync(() -> 5)
                .thenApply(i -> i * 3)
                .thenAccept(i -> System.out.println("the result is " + i))
                .thenRun(() -> System.out.println("Finished"));
        try {
            System.out.println("Ready to sleep ...");
            Thread.sleep(3000);
        } catch (Exception e) {}

    }
}
